package com.study.springmvc.web.controller;

import com.study.springmvc.model.Member;
import com.study.springmvc.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Description:
 * User: Administrator
 * DateTime: 2017/6/13 0013 21:40
 */
@Controller
@RequestMapping("/member")
public class MemberController {
	@Autowired
	private AccountService accountService;

	public MemberController() {
		StackTraceElement[] elements = Thread.currentThread().getStackTrace();
		for(int i=elements.length-1; i>=0; i--){
			System.out.println(elements[i].getClassName() + "  method " + elements[i].getMethodName());
		}
//		for (StackTraceElement element : elements) {
//			System.out.println(element.getClassName() + "  method " + element.getMethodName());
//		}

		System.out.println("\n\n\n");
	}

	@RequestMapping("/transfer")
	@ResponseBody
	public String transfer(@RequestParam("member") String memberId, int gold) {
		return accountService.transfer(memberId, gold);
	}

	@RequestMapping("/transfer1")
	@ResponseBody
	public String transfer(Member member) {
		return member.toString();
	}

	@RequestMapping("/test")
	@ResponseBody
	public Member member(@RequestBody Member member ) {
		return member;
	}
}
